#/*************************************************************************
#    > File Name: examples/example_Plot.py
#    > Author: Yan Wang
#    > Mail: wangyan@imnu.edu.cn
#    > Created Time: 2022年06月23日 星期四 14时20分04秒
# ************************************************************************/
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys    
sys.path.append('../Lib/')    
from Load_Lib import *     


print("The examples in this file are:")  
ex_name={"1":"Generate_Hotmap_Data_from_Para_and_Value"
,"2":"JGenerate_Hotmap_Data_from_List"
,"all":"all examples"}    #字典，所有对应函数为Lib/Plot_Data_Operation.py
for key in ex_name:
	print(key, ex_name[key])       #if条件语句，如果key在ex_name里面，则输出eg：1 Generate_Hotmap_Data_from_Para_and_Value
num=input("请输入想要运行的例子：")


if num == "1" or num == ex_name["1"] or num == "all":
# Generate_Hotmap_Data_from_Para_and_Value
# 五个参数(A,B,C,D,E),A为读取的数据文件,B为需要读取的列表,(A,B两参数被用于Load_THDM_Param(List_Operation)),C为输出文件的数据值,D为输出文件,E输出文件的title
# 输出用于绘制hotmap的数据文件
# 最后输出为："./examples/test_output/xection_w4b_para_and_value.dat"文件
# 并且文件中的title被换为：Double_t Parton_xection[（.tsv的行数---14行）][3]
# Double_t Parton_xection[14][3]=
# {{28.93582,85.57786800000001,2156.1817828335274},
# {27.506943,93.766289,1578.9800394544202},
# {20.960417,106.37348600000001,950.8009475414923},
# ......共14行数据
	parafile_name="examples/test_input/data_grid_mh_mch.tsv"   
	df = pd.read_table(parafile_name)   
	df_para=["mh","mch"]
	cut_cross=df["xsh_W4b"]
	hotmap_out_file="./examples/test_output/xection_w4b_para_and_value.dat"   
	hotmap_variable_name="Parton_xection"
	hot_map_data=Exhibit_Function(Generate_Hotmap_Data_from_Para_and_Value, [parafile_name, df_para, cut_cross ,hotmap_out_file,hotmap_variable_name])


if num == "2" or num == ex_name["2"] or num == "all":
# Generate_Hotmap_Data_from_List
# 与以上函数作用相同
# 最后输出为"examples/test_input/data_grid_mh_mch.tsv"文件
# Double_t Parton_xection[14][3]=
# {{28.93582,85.57786800000001,2156.1817828335274},
# {27.506943,93.766289,1578.9800394544202},
# {20.960417,106.37348600000001,950.8009475414923},
# ......共14行数据
	parafile_name="examples/test_input/data_grid_mh_mch.tsv"
	df = pd.read_table(parafile_name)
	para=[]
	para.append(df["mh"].to_list())   
	para.append(df["mch"].to_list())
	para.append(df["xsh_W4b"].to_list())
	hotmap_out_file="./examples/test_output/xection_w4b_list.dat"
	hotmap_variable_name="Parton_xection"
	hot_map_data=Exhibit_Function(Generate_Hotmap_Data_from_List, [para,hotmap_out_file,hotmap_variable_name])


if num == "3" or num == ex_name["3"] or num == "all":
# Generate_Hotmap_Code
# 两个参数(A,B),A为.c文件,B为参数值
# 对以上文件中的[39,44,45,47,48,59,60,77]行数做替换
# 输出为"./examples/test_output/hotmap/test_hotmap.C" 文件
	bins=[10,10,120,9,80,170]   #对应于hotmap_Parton_xection.pdf中----横坐标10-120，纵坐标80-170，10×9个格子
	file_name="./examples/test_output/hotmap/test_hotmap.C"   

# 上面是为para 变量初始化做准备
	para={	"file_name": file_name,
			"bins":bins,
			"data_length":len(cut_cross),
			"var_name":hotmap_variable_name,
			"X_name":"M_h",
			"Y_name":"M_ch",
			}
	Generate_Hotmap_Code(hotmap_out_file, para)
